package threading;


import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 徐志荣
 * @date 2023/3/26 10:52
 */
public class ThreadDemo26 {

    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                //num++
                num.getAndIncrement();
                //++num
                num.incrementAndGet();
                num.decrementAndGet();
                num.getAndDecrement();
            }
        });
        Thread t2 = new Thread(() ->{
            for (int i = 0; i < 50000; i++) {
                num.getAndIncrement();
            }

        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(num.get());
    }
}
